<?php
namespace Admin\Controller;
class AdminController extends BaseController {
    public function index(){
    	$data= M('admin_user')->alias('c')->field('c.id,c.user,c.time,c.status,g.name')->join('join boe_guanli g on c.pid=g.id')->select();
        //dump($data);
        $count = M('admin_user')->count();
        $this->assign('count',$count);
        $this->assign('data',$data);
        $this->display();
    }
    public function add(){
    	if(IS_POST){
    		$_POST['pass']=md5($_POST['pass']);
            $_POST['time']=time();
    		$res= M('admin_user')->add($_POST);
    		if($res){
    			$this->success('添加成功',U('Admin/index'));
    		}else{
    			$this->error('添加失败,请稍后重试');
    		}
    	}else{
    	$data = M('guanli')->select();
    	$this->assign('data',$data);
    	$this->display();
    	}
    	

    }
    public function edit(){
        $id = I('id');
        $data1 = M('guanli')->select();
        $data = M('admin_user')->where('id ='.$id)->find();
        $this->assign('data',$data);
        $this->assign('data1',$data1);
        $this->display();
    }
    public function status(){
        $res = M('admin_user')->save($_POST);
        if($res){
            $this->ajaxReturn(1);
        }else{
            $this->ajaxReturn(0);
        }
    }
    public function del(){
        $res = M('admin_user')->where($_POST)->delete();
        if($res){
            $this->ajaxReturn(1);
        }else{
            $this->ajaxReturn(0);
        }
    }
}